package db_DIEZWEITE;

import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyFrame extends Frame implements ActionListener {
	private Panel loginPanel = new Panel();
	private MyLabel lUsername = new MyLabel(20, 50, "Username");
	private MyTextField tfUsername = new MyTextField(150, 50);
	private MyLabel lPassword = new MyLabel(20, 100, "Password");
	private MyTextField tfPassword = new MyTextField(150, 100);
	private MyButton bOK = new MyButton(20, 150, "OK");
	private MyButton bCancel = new MyButton(150, 150, "Cancel");
	
	public static void main(String[] args) {
		new MyFrame();
	}
	
	public MyFrame() {
		setSize(400, 300);
		setLocation(200, 200);
		setTitle("Hallo Welt");
		getLoginPanel().setLayout(null);
		add(loginPanel);
		getLoginPanel().add(lUsername);
		getLoginPanel().add(tfUsername);
		getLoginPanel().add(lPassword);
		getLoginPanel().add(tfPassword);
		getLoginPanel().add(bOK);
		getLoginPanel().add(bCancel);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent event) {
				dispose();
			}
		});
		bOK.addActionListener(this);
		bCancel.addActionListener(this);
		setVisible(true);
	}
	
	public Panel getLoginPanel() {
		return loginPanel;
	}

	public void setLoginPanel(Panel loginPanel) {
		this.loginPanel = loginPanel;
	}
	

	public MyLabel getlUsername() {
		return lUsername;
	}

	public void setlUsername(MyLabel lUsername) {
		this.lUsername = lUsername;
	}

	public MyTextField getTfUsername() {
		return tfUsername;
	}

	public void setTfUsername(MyTextField tfUsername) {
		this.tfUsername = tfUsername;
	}

	public MyLabel getlPassword() {
		return lPassword;
	}

	public void setlPassword(MyLabel lPassword) {
		this.lPassword = lPassword;
	}

	public MyTextField getTfPassword() {
		return tfPassword;
	}

	public void setTfPassword(MyTextField tfPassword) {
		this.tfPassword = tfPassword;
	}

	public MyButton getbOK() {
		return bOK;
	}

	public void setbOK(MyButton bOK) {
		this.bOK = bOK;
	}

	public MyButton getbCancel() {
		return bCancel;
	}

	public void setbCancel(MyButton bCancel) {
		this.bCancel = bCancel;
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("OK")) {
			String username = getTfUsername().getText();
			String password = getTfPassword().getText();
			System.out.println(username + " identified by " + password + " is trying to connect to database...");
		} else {
			System.out.println("Closing connection...");
		}		
	}
}